package com.common.response;

import com.common.comm.ResultEnum;
import com.common.comm.ResultEnumInterface;
import com.common.exception.CommException;

/**
 * @ClassName ResultUtil
 * @Description 响应基本参数
 * @Author zhanghaiwen
 * @Date 2020/1/9 14:34
 * @Version 6.1.1
 **/
@SuppressWarnings("unchecked")
public class ResultUtil {
    //自定义返回成功类型
    public static Result SUCCESS() {
        return SUCCESS(ResultEnum.SUCCESS);
    }

    //自定义返回数据类型
    public static Result SUCCESS(Object object) {
        Result result = Result.builder()
                .code(ResultEnum.SUCCESS.getCode())
                .msg(ResultEnum.SUCCESS.getMsg())
                .data(object).build();
        return result;
    }

    //自定义返回失败数据类型
    public static Result SUCCESS(ResultEnumInterface resultEnumInterface) {
        Result result = Result.builder()
                .code(resultEnumInterface.getCode())
                .msg(resultEnumInterface.getMsg())
                .data(null).build();
        return result;
    }

    //自定义返回失败数据类型
    public static Result SUCCESS(CommException commException) {
        Result result = Result.builder()
                .code(commException.getCode())
                .msg(commException.getErrorMsg())
                .data(null).build();
        return result;
    }
}
